
package logic.forms;

import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import logic.beans.DBElementIF;

import org.apache.struts.action.ActionForm;

public class ElementForm<E extends DBElementIF> extends ActionForm {
	private static final long serialVersionUID = 1L;
	
	protected E element = null;
	
	@SuppressWarnings("unchecked")
	public ElementForm() {
		super();
		try {
			this.element = ((Class<E>)((ParameterizedType)this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}
	
	public E getElement() {
		return element;
	}
	
	public List<String> getEmptyPropertyNames() {
		return new ArrayList<String>();
	}
	
	protected boolean isFieldEmpty(String property) {
		return property == null || property.isEmpty();
	}
	
	public void setup(HttpServletRequest request) {
		setElementFromRequest(request);
		setRequestFromElement(request);
	}
	
	public void setElementFromRequest(HttpServletRequest request) {
	}
	
	public void setRequestFromElement(HttpServletRequest request) {
	}
}
